<?php
include "../../public/common/config.php";
include "../../public/common/function.php";
//echo '<pre>';
//print_r($_POST);
//echo '</pre>';
//
//echo '<pre>';
//print_r($_FILES);
//echo '</pre>';
//exit;

$name = $_POST['name'];
$price = $_POST['price'];
$stock = $_POST['stock'];
$shelf = $_POST['shelf'];
$brand_id = $_POST['brand_id'];

//图片上传
$src = $_FILES['img']['tmp_name'];
$fname = $_FILES['img']['name'];
$a = explode('.',$fname);
$ext = array_pop($a);
$dst = '../public/uploads/'.time().mt_rand().'.'.$ext;

//如果图片上传成功，则生成缩略图
if(move_uploaded_file($src,$dst)){
	//进行图片缩放200X200
	thumb($dst,200,200);
	$img = basename($dst);
	
	$sql = "insert into shop(name,price,stock,shelf,brand_id,img) values('{$name}','{$price}','{$stock}','{$shelf}','{$brand_id}','{$img}')";
//	echo $sql;exit;

	if(mysql_query($sql)){
		echo '<script>location="index.php"</script>';
	}
}



?>